package com.zhou.blog.controller;

import com.zhou.blog.common.aop.Cache;
import com.zhou.blog.common.aop.LogAnnotation;
import com.zhou.blog.service.ArticleService;
import com.zhou.blog.vo.Result;
import com.zhou.blog.vo.params.ArticleParam;
import com.zhou.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @title:ArticleController
 * @Author Zhou
 * @Date:2022/4/11 22:01
 * @Version 1.0
 */
//json数据交互
@RestController
@RequestMapping("api/articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    @LogAnnotation(module = "文章",operator = "文章列表")
    @Cache(expire = 5 * 60 * 1000,name = "article_listArticle")
    public Result listArticle(@RequestBody PageParams pageParams){
        return articleService.listArticle(pageParams);
    }

    @PostMapping("/hot")
    @Cache(expire = 5 * 60 * 1000,name = "article_hot")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArticle(limit);
    }

    @PostMapping("/new")
    @Cache(expire = 5 * 60 * 1000,name = "article_new")
    public Result newArticle(){
        int limit = 5;
        System.out.println(articleService.newArticles(limit).toString());
        return articleService.newArticles(limit);
    }

    @PostMapping("listArchives")
    public Result listArchives(){
        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id){
        return articleService.findArticleById(id);
    }

    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }


}
